package com.glory.cqaospda.view

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Message
import android.util.Log
import android.view.KeyEvent
import android.view.View
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.glory.cqaospda.R
import com.glory.cqaospda.adapter.FixtureBindAdapter
import com.glory.cqaospda.adapter.LotEndAdapter
import com.glory.cqaospda.base.Constant
import com.glory.cqaospda.base.MyApp
import com.glory.cqaospda.bean.RunLotHiBean
import com.glory.cqaospda.viewmodel.LogtEndModel
import com.glory.mvvmnet.base.BaseActivity
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ActivityManager
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils
import kotlinx.android.synthetic.main.activity_lotend.*
import kotlinx.android.synthetic.main.activity_title.*
import kotlinx.android.synthetic.main.lotend_layout.*

class LotEndActivity:BaseActivity<LogtEndModel>() {
    private lateinit var runLotHiBeanList: ArrayList<RunLotHiBean>
    var mLotEndAdapter: LotEndAdapter? = null

    override fun initData() {

        initRecyclerView(rvLotList, this)
        mLotEndAdapter = LotEndAdapter(runLotHiBeanList[0].parameterlist)
        rvLotList.adapter = mLotEndAdapter

    }

    override fun initView(savedInstanceState: Bundle?) {
        tvBaseSubmit.visibility = View.GONE
        markLead.visibility = View.GONE
        tvTitle.text = "停止当前作业"
        tvUserName.text = Constant.UserName
        FreeApi_ActivityManager.getActivityManager().addActivity(this)

        runLotHiBeanList = intent.getSerializableExtra("runLotHiBeanList") as ArrayList<RunLotHiBean>
        tvHandle.text = intent.getStringExtra("EquipmentName").toString()
        tvEAPstate.text = intent.getStringExtra("EquipmentStatus").toString()
        tvMESstate.text = intent.getStringExtra("EquipmentStatus").toString()
//        tvMark.text = intent.getStringExtra("mark").toString()
//        tvLead.text = intent.getStringExtra("lead").toString()
        tvYield.text = runLotHiBeanList[0].yield

//        tvNo.text = runLotHiBeanList.get(0).parameterlist.get(0).no
//        tvName.text = runLotHiBeanList.get(0).parameterlist.get(0).parametermame
//        tvQty.text = runLotHiBeanList.get(0).parameterlist.get(0).parameternumber
//        tvBad.text = runLotHiBeanList.get(0).parameterlist.get(0).parameteryield

        lineEnd.setOnClickListener{
            if (Constant.isFastClick()) {
                finish()
            }
        }
    }

    override fun layoutId(): Int {
        return R.layout.activity_lotend
    }

    protected fun initRecyclerView(recyclerView: RecyclerView, context: Context?) {
        recyclerView.layoutManager = LinearLayoutManager(context)
        recyclerView.itemAnimator = DefaultItemAnimator()
        recyclerView.addItemDecoration(DividerItemDecoration(context, 1))
    }

    @SuppressLint("SetTextI18n")
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (requestCode == 1) {
            when (resultCode) {
                108 -> {
                    finish()
                }
            }
        }
    }
    override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK){
            intent.putExtra("type", "KeyEvent")
            intent.setClass(this, SkipDialogActivity::class.java)
            startActivityForResult(intent, 1)
            return false
        }
        return super.onKeyUp(keyCode, event)
    }
}